#ifndef _ITEM_DBEVENT_H_
#define _ITEM_DBEVENT_H_

#include "sddb.h"
#include "ISProto.h"
#include "trademgr.h"
#include "mailmgr.h"

using namespace SGDP;

class CBaseEvent : public ISDDBCommand
{
public:
    CBaseEvent();
protected:
    virtual INT32 SDAPI GetDBSn(void);
    virtual void SDAPI Release(void);

    bool _ExcuteProcedure(char* pszSQL, ISDMySqlConn* poDBConnection);
    bool _ExcuteProcedureRC(char* pszSQL, ISDMySqlConn* poDBConnection, ISDMySqlRecordSet** ppoRc=NULL);

protected:
    UINT32  m_dwTransID;
    UINT32  m_dwRoleID;
    bool    m_bOpSuc;
    ISDMySqlRecordSet* m_poRecordSet;
};

class CGetEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, UINT32 dwRoleID);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);
};

class CCreateEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, UINT32 dwRoleID, const ::google::protobuf::RepeatedPtrField<ItemInfo> & Items);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);

private:
    ::google::protobuf::RepeatedPtrField<ItemInfo> m_Items;
};

class CUseEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, UINT32 dwRoleID, const ::google::protobuf::RepeatedPtrField<ItemBaseInfo> & Items);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);

private:
    //SItemBaseInfo m_stItemBaseInfo[MAX_ITEM_USE];
    ::google::protobuf::RepeatedPtrField<ItemBaseInfo> m_Items;

};

class CAddQuantityEvent: public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, UINT32 dwRoleID, const ItemBaseInfo & item, UINT32 dwCount);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);
private:
    ItemBaseInfo m_item;
    UINT32  m_dwCount;
};

class CComplexEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, UINT32 dwRoleID, const ::google::protobuf::RepeatedPtrField<ItemInfo> & CreateItemsInfos, const ::google::protobuf::RepeatedPtrField<ItemBaseInfo> & UseItemsBaseInfos);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);

private:
    ::google::protobuf::RepeatedPtrField<ItemInfo> m_CreateItemsInfos;
    ::google::protobuf::RepeatedPtrField<ItemBaseInfo> m_UseItemsBaseInfos;
};

class CChangeEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, UINT32 dwRoleID, const ::google::protobuf::RepeatedPtrField<ChangePosInfo> & ChangeInfos);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);

private:
    ::google::protobuf::RepeatedPtrField<ChangePosInfo> m_ChangeInfos;
};

class CTradeEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, STTRADERECORD* pstRecord);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);

private:
    STTRADERECORD m_stTradeRecord;
};

class CMailSendEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, STMAILRECORD* pstMailRecord);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);
private:
    STMAILRECORD m_stMailRecord;
};

class CMailRecvEvent : public CBaseEvent
{
public:
    bool Init(UINT32 dwTransID, STMAILRECORD* pstMailRecord);
    virtual void SDAPI OnExecuteSql(ISDMySqlConn* poDBConnection);
    virtual void SDAPI OnExecute(void);
private:
    STMAILRECORD m_stMailRecord;
};




#endif